package com.ajx.core.net.rest.function;

import com.ajx.core.net.rest.HttpResponse;
import com.ajx.core.net.rest.exception.ServerException;
import com.google.gson.Gson;

import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Function;

public class ServerResultFunction implements Function<HttpResponse, Object> {
    @Override
    public Object apply(@NonNull HttpResponse response) throws Exception {
        //打印服务器回传结果

        if (!response.isSuccess()) {
            throw new ServerException(response.getResult(), response.getMessage());
        }
        return new Gson().toJson(response.getData());
    }
}